<template>
	<div class="v-upload">
		<upload-image
			v-if="type === 'image'"
			:disabled="disabled"
			:read-only="readOnly"
			:max="max"
			ref="uploadImageRef"
			key="image"
		></upload-image>
		<upload-video
			v-else-if="type === 'video'"
			:disabled="disabled"
			:read-only="readOnly"
			:max="max"
			ref="uploadVideoRef"
			key="video"
		></upload-video>
	</div>
</template>

<script>
import UploadImage from "./uploadImage/index.vue"
import UploadVideo from "./uploadVideo/index.vue"

export default {
	name: "v-upload",
	props: {
		type: {
			type: String,
			default: "image", // image video
		},
		disabled: {
			type: Boolean,
			default: false,
		},
		readOnly: {
			type: Boolean,
			default: false,
		},
		max: {
			type: [Number, String],
			default: -1,
		},
	},
	data() {
		return {}
	},
	computed: {},
	methods: {
		setFileList(list = []) {
			if (this.type === "image") {
				this.$refs.uploadImageRef.fileList = [].concat(list)
			} else if (this.type === "video") {
				this.$refs.uploadVideoRef.fileList = [].concat(list)
			}
		},
		getFileList() {
			if (this.type === "image") {
				return [].concat(this.$refs.uploadImageRef.fileList)
			} else if (this.type === "video") {
				return [].concat(this.$refs.uploadVideoRef.fileList)
			}
		},
	},
	components: {
		UploadImage,
		UploadVideo,
	},
}
</script>

<style lang="scss" scoped>
.v-upload {
}
</style>
